package org.aeon.heroicsagatextedition.role.product;

import java.util.Random;

/**
 * @projectName: HeroicSagaTextEdition
 * @package: org.aeon.heroicsagatextedition.role.product
 * @className: RoleUnit
 * @author: MissingAeon
 * @date: 2023/12/22 13:03
 * @description: 角色抽象类
 */
public abstract class RoleUnit implements Cloneable {
    protected String name;          // 姓名
    protected int hp;               // 血量
    protected int maxHp;            // 最大血量
    protected int maxAttack;        // 最大攻击力
    protected int minAttack;        // 最小攻击力

    protected String describe;      // 描述

    // 救命药丸：英雄总共拥有三颗，若使用此救命药丸，每次使用，可以挽回100点生命值，当使用后，生命值超过600，则只能加到600；每轮使用救命药丸，则当轮英雄无法进行攻击动作
    protected int lifeSavingPillCount = 3;

    public RoleUnit(String name, int maxHp) {
        this.name = name;
        this.maxHp = maxHp;
        this.hp = maxHp;
    }

    public RoleUnit(String name, int maxHp, int maxAttack, int minAttack) {
        this.name = name;
        this.maxHp = maxHp;
        this.hp = maxHp;
        this.maxAttack = maxAttack;
        this.minAttack = minAttack;
    }


    /**
     * 获取最大最小之间的随机攻击力
     *
     * @return
     */
    public int getAttack() {
        return new Random().nextInt(maxAttack - minAttack + 1) + minAttack;
    }

    /**
     * 获取角色是否死亡
     *
     * @return
     */
    public boolean isSurvival() {
        return hp > 0;
    }

    /**
     * 判断是否满血
     *
     * @return
     */
    public boolean isFullOfHp() {
        return hp >= maxHp;
    }

    public boolean usingPills() {
        return false;
    }

    public void hpChanged(int increment) {
        hp += increment;
    }

    public abstract int getCamp();

    public int getLifeSavingPillCount() {
        return lifeSavingPillCount;
    }

    public String getName() {
        return name;
    }

    public int getHp() {
        return hp;
    }

    /**
     * 复制重写
     *
     * @return
     */
    @Override
    public RoleUnit clone() {
        try {
            RoleUnit clone = (RoleUnit) super.clone();
            return clone;
        } catch (CloneNotSupportedException e) {
            throw new AssertionError();
        }
    }
}
